import store from '../store'

function hasPermission(myarray, el=null) {
    const ruleNames = store.state.user.ruleNames
    let hasAuth = false
    if(ruleNames && Array.isArray(myarray)) {
        hasAuth =  myarray.every(item => ruleNames.includes(item))
    }
    if(el && !hasAuth) {
        el.parentNode && el.parentNode.removeChild(el)
    }
    return hasAuth
}

export default {
  install(app) {
    // 使 v-focus 在所有组件中都可用
    app.directive("permission", {
      /* ... */
      mounted(el, binding, vnode) {
        hasPermission(binding.value, el)
      },
    });
  },
};
